from peewee import *

db = MySQLDatabase('test',
                   **{'charset': 'utf8', 'sql_mode': 'PIPES_AS_CONCAT', 'use_unicode': True, 'user': 'root',
                      'password': 'root'})


class UnknownField(object):
    def __init__(self, *_, **__): pass


class BaseModel(Model):
    class Meta:
        database = db


class User(BaseModel):
    age = IntegerField(null=True)
    birthday = DateTimeField(null=True)
    name = CharField(null=True)

    class Meta:
        table_name = 'user'


# 批量插入：字典
data = [
    {'name': '张三1', 'age': 33, 'birthday': '2001-1-1'},
    {'name': '张三2', 'age': 33, 'birthday': '2001-1-1'},
    {'name': '张三3', 'age': 33, 'birthday': '2001-1-1'},
    {'name': '张三4', 'age': 33, 'birthday': '2001-1-1'},
    {'name': '张三5', 'age': 33, 'birthday': '2001-1-1'},
    {'name': '张三6', 'age': 33, 'birthday': '2001-1-1'},
]

User.insert_many(data).execute()
